#include "mainwidget.h"
#include "ui_mainwidget.h"


MainWidget::MainWidget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::MainWidget)
{
    ui->setupUi(this);
    form01 = new Form01();
    form02 = new Form02();
    form03 = new Form03();


    // 处理stackedWidget
    this->ui->stackedWidget->addWidget(form01);
    this->ui->stackedWidget->addWidget(form02);
    this->ui->stackedWidget->addWidget(form03);
    // 处理
    model = new QStandardItemModel(3, 1);
    model->setHeaderData(0, Qt::Horizontal, tr("页面名称"));
    QStandardItem* item1 = new QStandardItem("页面1");
    QStandardItem* item2 = new QStandardItem("页面2");
    QStandardItem* item3 = new QStandardItem("页面3");

    model->setItem(0, 0, item1);
    model->setItem(1, 0, item2);
    model->setItem(2, 0, item3);
    this->ui->treeView->setModel(model);
    //设置无法编辑
    this->ui->treeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
}

MainWidget::~MainWidget()
{
    delete ui;
}


void MainWidget::on_treeView_doubleClicked(const QModelIndex &index)
{
    //判断是否是鼠标左键，可以重写点击点击事件，传递 QMouseEvent* event，在抛出页面信号
    switch (index.row()) {
    case 0:
    {
        this->ui->stackedWidget->setCurrentWidget(form01);
        break;
    }
    case 1:
    {
        this->ui->stackedWidget->setCurrentWidget(form02);
        break;
    }
    case 2:
    {
        this->ui->stackedWidget->setCurrentWidget(form03);
        break;
    }
    default:
        break;
    }
}
